package gupao.concurrency.lock;

import com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockSample {

    public static void main(String[] args) {
        boolean fair = false;
        Lock lock = new ReentrantLock(fair);


        try{
            lock.lockInterruptibly();
            doTask();
        } catch (InterruptedException e) {
            //根据需要处理你的中断异常
        } finally {
            lock.unlock();
        }

        boolean tryLock = false;
        try {
            tryLock = lock.tryLock(1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        if(tryLock){
            try{
                doScheduleTask();
            }finally {
                lock.unlock();
            }
        }
    }

    static void doTask(){

    }
    static void doScheduleTask(){

    }
}
